package modelLayer;

import java.util.ArrayList;

import controllerLayer.ProductCtr;

public class Contractor {
private String Id;
private String name;
private String address;
private String phoneNr;
private ArrayList<Product> products;
private double moneyPaid;
public Contractor(String id, String name, String address,String phoneNr) {
	Id = id;
	this.name = name;
	this.address = address;
	this.phoneNr = phoneNr;
	moneyPaid = 0;
	products = new ArrayList<Product>();
}
@Override
public String toString() {
	return "Contractor [Id=" + Id + ", name=" + name + ", address=" + address
			+ ", phoneNr=" + phoneNr + ", products=" + products
			+ ", moneyPaid=" + moneyPaid + "]";
}
public String getPhoneNr() {
	return phoneNr;
}
public void setPhoneNr(String phoneNr) {
	this.phoneNr = phoneNr;
}
public String getId() {
	return Id;
}
public void setId(String id) {
	Id = id;
}
public String getName() {
	return name;
}
public void setName(String name) {
	this.name = name;
}
public String getAddress() {
	return address;
}
public void setAddress(String address) {
	this.address = address;
}
public double getMoneyPaid() {
	for(Product product: products){
		moneyPaid = moneyPaid + product.getQuantity()*product.getPrice();
	}
	return moneyPaid;
}
public void setMoneyPaid(double moneyPaid) {
	this.moneyPaid = moneyPaid;
}
public ArrayList<Product> getProducts() {
	return products;
}
public void addProduct(String prodID){
	ProductCtr pctr = new ProductCtr();
	Product product = pctr.getItem(prodID);
	products.add(product);
	
}
public String save() {
	
String ids = "";
for(Product p1:products){
try{	ids = ids+p1.getId()+",";
}
catch(NullPointerException npe){
	
}
}
return 5+","+ Id+","+name+","+address+","+phoneNr+","+moneyPaid+","+ids;
	}
public void setProducts(ArrayList<Product> products) {
	this.products = products;
}
}



